<?php
function check_email_address($email) {
    if (!preg_match("/^[[:alnum:]][a-z0-9_.-]*@[a-z0-9.-]+\.[a-z]{2,4}$/i", $email)) {
        return false;
    } else {
        return true;
    }
}
function createRandomKey($amount){
    $keyset = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
    $randkey = "";
    for ($i=0; $i<$amount; $i++) {
      if ($i % 4 == 0 && $i > 0) {
        $randkey .= "-";
      }
      $randkey .= substr($keyset, rand(0, strlen($keyset)-1), 1);
    }
    return $randkey;
}
//Display error messages
// message - The message to be displayed
// action - The page that will be sent to, if unset, browser will do a back action
function error($message, $action = null) {
  echo "<script>
        $(document).ready(function() {
            wtd.alert.showMessage('".$message."', {
                 callback: function() {
        ";
        if ($action) {
          echo "window.location='".$action."';";
        } else {
          echo "history.go(-1);";
        }
        echo "
                 }
             });
        });
        </script>";  
}
function redimensiona($filename, $tmpname, $xmax = 160, $ymax = 160) {
    $ext = explode(".", $filename);       
    $ext = $ext[count($ext)-1];
    if($ext == "jpg" || $ext == "jpeg")
        $im = imagecreatefromjpeg($tmpname);
    elseif($ext == "png")
        $im = imagecreatefrompng($tmpname);
    elseif($ext == "gif")
        $im = imagecreatefromgif($tmpname);
    $x = imagesx($im);
    $y = imagesy($im);
    if($x <= $xmax && $y <= $ymax)
        return $im;
    if($x >= $y) {
        $newx = $xmax;
        $newy = $newx * $y / $x;
    }
    else {
        $newy = $ymax;
        $newx = $x / $y * $newy;
    }
    $im2 = imagecreatetruecolor($newx, $newy);
    imagecopyresized($im2, $im, 0, 0, 0, 0, floor($newx), floor($newy), $x, $y);
    return $im2;
}

function urlimage($photo, $type){
	include('config.php');
	$url = $CONFIG_image_host;
	switch ($type){
		default:
		case "user":
			$url .= $CONFIG_image_path_user.$photo;
			break; 
		case "places":
			$url .= $CONFIG_image_path_places.$photo;
			break;
		case "events":
			$url .= $CONFIG_image_path_events.$photo;
			break;
		case "gallery":
			$url .= $CONFIG_image_path_gallery.$photo;
			break;
	}
	if($photo == ""){
			$url = "images/fotoperfil.png";
	} else if(substr($photo, 0, 7) == "http://") {
		$url = $photo;
	}
	return $url;
}
function createThumbs($photo, $largura_fixa, $altura_fixa){
	
    $source = $photo;

	if(!file_exists($source))
	{
		echo "Arquivo da imagem não encontrado!";
		exit;
	}

	$arquivo_miniatura = explode('.', $source);
	$arquivo_miniatura = $arquivo_miniatura[0]."mini.jpg";

	$img_origem = imagecreatefromjpeg($source);
	$origem_x = imagesx($img_origem);
	$origem_y = imagesy($img_origem);

	$x = $largura_fixa;
	$y = $altura_fixa;
	
	$img_final = imagecreatetruecolor($x, $y);
	imagecopyresampled($img_final, $img_origem, 0, 0, 0, 0, $x+1, $y+1, $origem_x, $origem_y);
	imagejpeg($img_final, $arquivo_miniatura);
	
	return $arquivo_miniatura;
      
}
function MailUser(){
	$mail = "whatoodo@whatoodo.com";
	return $mail;
}
function MailPasswd(){
	$passwd = "123mudar";
	return $passwd;
}
function MailHost(){
	$host = "mail.whatoodo.com";
	return $host;
}
?>
